//
//  MYGMedicalToolsHomeCell.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/10.
//

import UIKit

class MYGMedicalToolsHomeCell: UICollectionViewCell {
    // MARK: - Property
    var type: MYGMedicalToolsType? {
        didSet {
            guard let type = type else { return }
            line.backgroundColor = type.themeColor
            titleLabel.text = type.title
        }
    }
    
    
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        configUI()
    }
        
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.addSubviews([
            cardView
        ])
        
        cardView.addSubviews([
            line,
            titleLabel,
            arrowImageView
        ])
        
        cardView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        
        line.snp.makeConstraints { make in
            make.height.equalTo(40)
            make.width.equalTo(3)
            make.centerY.equalToSuperview()
            make.left.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(15)
            make.right.equalTo(-8)
        }
        
        arrowImageView.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.bottom.equalTo(-15)
        }
    }
    
    // MARK: - lazy load
    private lazy var cardView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.layer.cornerRadius = 5
        view.clipsToBounds = false
        view.layerShadowColor = .rgba(0, 0, 0, 0.1)
        view.layerShadowOffset = CGSize(width: 0, height: 0)
        view.layerShadowOpacity = 1
        view.layerShadowRadius = 5
        return view
    }()
    
    private lazy var line: UIView = {
        let view = UIView()
        return view
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(14)
        label.textColor = .rgba(51, 51, 51)
        return label
    }()
    
    private lazy var arrowImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "MYG_tools_arrow"))
        return imageV
    }()
}
